var SLIDESHOW = {
    timerId: null,
    stop: function() {
	clearTimeout(SLIDESHOW.timerId);
    },
    start: function() {
	SLIDESHOW.timerId = window.setInterval(SLIDESHOW.switchToNext, 8000);		
    },
    container : null,
    getContainer: function() {
	if (!SLIDESHOW.container) {
	    $("#slideshow p").text($("#slideshow img").attr("alt"));
	    SLIDESHOW.container = $("#slideshow");
	}
	return SLIDESHOW.container;
    },
    switchToNext: function() {
	container = SLIDESHOW.getContainer();
	var newImage
	    = SLIDESHOW.getContainer().find("img").css("z-index", "2").eq(1)
	    .css("z-index", "1").show();
	var oldImage
	    = SLIDESHOW.getContainer().find("img").eq(0)
	    .fadeOut(2700, function() {
		oldImage.appendTo($("#slideshow"));					
	    });
	SLIDESHOW.updateOverlay(newImage.attr("alt"));
    },
    updateOverlay: function(newCaption) {
	var oldP = this.container.find(".overlay p")
	    .hide("slide", {direction: "left"}, 1300, function() {
		oldP.detach();
		$("<p></p>").text(newCaption)
		    .appendTo(SLIDESHOW.getContainer().find(".overlay")).show()
		    .css({
			"position":"absolute",
			"left": -350
		    }).animate({
			"left": 0
		    }, 2000);
	    });
    }
}